package com.uy.system.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.uy.system.model.dto.SysUserDTO;
import com.uy.system.model.entity.SysUser;
import com.uy.system.model.form.SysUserFrom;
import com.uy.system.model.vo.SysUserVo;
import com.uy.system.response.ResponseMessage;
import com.uy.system.response.ResponseMessageFactory;
import com.uy.system.service.ISysUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 用户信息表 前端控制器
 * </p>
 *
 * @author ly
 * @since 2024-03-22
 */
@Tag(name = "用户信息接口文档")
@RestController
@RequestMapping("/sysUser")
@RequiredArgsConstructor
public class SysUserController {

    private final ISysUserService iSysUserService;

    @Operation(summary = "获取用户信息列表")
    @Parameters({
            @Parameter(name = "accessToken",description = "请求token",required = true,in = ParameterIn.HEADER)
    })
    @SaCheckPermission("system:user:query")
    @GetMapping("/querySysUser")
    public ResponseMessage<Page<SysUser>> querySysUser(@ParameterObject SysUserDTO dto){
        return ResponseMessageFactory.getSuccessResponseMessage(iSysUserService.querySysUser(dto));
    }

    @Operation(summary = "保存或者编辑用户信息")
    @Parameters({
            @Parameter(name = "accessToken",description = "请求token",required = true,in = ParameterIn.HEADER)
    })
    @PostMapping("/addOrEditSysUser")
    public ResponseMessage<Void> addOrEditSysUser(@ParameterObject @RequestBody SysUserFrom from){
        iSysUserService.addOrEditSysUser(from);
        return ResponseMessageFactory.getSuccessResponseMessage();
    }

    @Operation(summary = "删除用户信息")
    @Parameters({
            @Parameter(name = "accessToken",description = "请求token",required = true,in = ParameterIn.HEADER)
    })
    @PostMapping("/delSysUserByUserId")
    public ResponseMessage<Void> delSysUserByUserId(@ParameterObject @RequestBody String userId){
        iSysUserService.delSysUserByUserId(Long.valueOf(userId));
        return ResponseMessageFactory.getSuccessResponseMessage();
    }

    @Operation(summary = "获取用户信息")
    @Parameters({
            @Parameter(name = "accessToken",description = "请求token",required = true,in = ParameterIn.HEADER)
    })
    @GetMapping("/getSysUserInfo")
    public ResponseMessage<SysUserVo> getSysUserInfo(@ParameterObject String userId){
        return ResponseMessageFactory.getSuccessResponseMessage(iSysUserService.getSysUserInfo(Long.valueOf(userId)));
    }
}
